/*/**						*/
/* * Persevere extension - This contains several extra functions that provide extra functionality.						*/
/* *    						*/

/*			pjs.introspect = function(target, callback,includeInherited) {						*/pjs.introspect=function(){with(_frm(this,arguments,["target","callback","includeInherited"],["i","instance"])){nj:while(1){switch(_cp){case 0:
/*					if (target.$_funcObj)						*/if(target.$_funcObj)
/*						target = target.$_funcObj;						*/{target=target.$_funcObj;}
/*					if (target._fldsMkCnc && target[":parentObject"]) // This indicates that it is the fields object, we may want to use a different indicator						*/if(target._fldsMkCnc&&target[":parentObject"])
/*						var instance = target[":parentObject"];						*/{instance=target[":parentObject"];}
/*					else						*/
/*						var instance = target;							*/ else instance=target;
/*					for (var i in instance) {						*/_r.iter0=njkeys(instance);_r.ctr0=0;case 2:_cp=(_r.ctr0<_r.iter0.length)?3:4;break;case 3:i=_r.iter0[_r.ctr0];
/*						if (typeof i == "string" && (includeInherited || instance.hasOwnProperty->(i)) && i != "parent" && i != "array") 						*/_cp=(typeof i=="string"&&(includeInherited||instance.hasOwnProperty(i))&&i!="parent"&&i!="array")?5:6;break;case 5:_cp=7;case 7:if((_r.v7=
/*						{						*/
/*							//debug(i + " " + instance[i]);						*/
/*							callback(i);						*/callback(i))===_S){return _s();}_cp=6;break;case 6:case 1:_r.ctr0++;_cp=2;break;case 4:
/*						}						*/
/*					}						*/
/*					if (instance['array']) {						*/_cp=(instance["array"])?8:9;break;case 8:
/*						if(target._fldsMkCnc)						*/_cp=(target._fldsMkCnc)?10:11;break;case 10:_cp=13;case 13:if((_r.v13=
/*							callback("items");						*/callback("items"))===_S){return _s();}_cp=12;break;case 11:
/*						else						*/
/*							for (var i=0;i<instance['array'].length;i++) {						*/i=0;case 15:_cp=(i<instance["array"].length)?16:17;break;case 16:_cp=18;case 18:if((_r.v18=
/*								callback(i);						*/callback(i))===_S){return _s();}case 14:i++;_cp=15;break;case 17:_cp=12;break;case 12:_cp=9;break;case 9:break nj;}}}};
/*							}						*/
/*					}						*/
/*/*					if (includeInherited && !target.isAccess)						*/
/*						callback("access");						*/
/*					if (includeInherited && !target._fldsMkCnc) {						*/
/*						callback("structure");												*/
/*					}* 						*/
/*					//return fields;						*/
/*				}						*/
/*			/** Sets the given field on this object *  						*/
/*		/** TODO: This should go on the history object, along with the some of the undo code in illum.editmode.js * 						*/
/*		/*this.undo = function(redo,historyEntry) {						*/
/*			var target = this.parent;						*/
/*			var version = target.$_undoVersion;						*/
/*			if (version === undefined) 						*/
/*				version = target.$_undoVersion = this.getLength();						*/
/*			if (!historyEntry)						*/
/*				historyEntry = this.item(version + (redo?1:-1));						*/
/*			if (version < this.getLength()) // on the first undo, we need to record it in history, so we can redo it						*/
/*				recordingHistory = false; // TODO: this may need to go on currentThread						*/
/*			pjs.introspect(historyEntry,function(field) { 						*/
/*				if (field != "modified" && field != "modifier" && field != "parent") {						*/
/*					var value = get(historyEntry,field);						*/
/*					if (field == "_basis")						*/
/*						field = "basis";						*/
/*					if (value instanceof String)						*/
/*						if (value.substring(0,6) == "diff:\\n") {						*/
/*							assert(!redo); // this should be changed so this doesn't happen						*/
/*							var diffString = value.substring(6);						*/
/*							value = get(target,field);						*/
/*					    	var indexAdjustment = 0;													*/
/*					    	do { // apply the merge values in reverse						*/
/*					    		var commandAndRest = diffString.split("\\n");						*/
/*					    		var command = commandAndRest[0];						*/
/*					    		var type = command.substring(command.length - 1);						*/
/*					    		var startAndEnd = command.substring(0,command.length - 1).split(",");						*/
/*					    		var start = parseInt(startAndEnd[0]);						*/
/*					    		var end = parseInt(startAndEnd[1]);						*/
/*					    		var addEnd = startAndEnd.length > 2? parseInt(startAndEnd[2]) : end;						*/
/*					    		commandAndRest[0] =""; // remove the command part and get the rest						*/
/*					    		diffString = commandAndRest.join();						*/
/*					    		var addition= diffString.substring(2,addEnd-start+2);						*/
/*					    		diffString = diffString.substring(addEnd-start+2);						*/
/*					    		if (diffString.length > 0)						*/
/*					    			diffString = diffString.substring(1);						*/
/*					    		if ("d"==type || "c"==type) 						*/
/*					    			value = value.substring(0,start +indexAdjustment) + value.substring(end + indexAdjustment); 						*/
/*					    		if ("a"==type || "c"==type) {						*/
/*									value = value.substring(0,start + indexAdjustment) + addition + value.substring(start + indexAdjustment); 						*/
/*									indexAdjustment += addition.length;						*/
/*					    		}						*/
/*					    		if ("d"==type || "c"==type)						*/
/*					    			indexAdjustment += start - end; // must be done afterwards so it doesn't alter the addition operation						*/
/*					    	}						*/
/*					    	while (diffString.length > 0);						*/
/*					    	historyEntry.isLocal = true;						*/
/*					    	set(historyEntry,field,value);// just store the result of the merge because it is too hard to figure it out in double reverse for merge						*/
/*						}						*/
/*					set(target,field,value);						*/
/*				}						*/
/*			});						*/
/*			recordingHistory = true;						*/
/*			target.$_undoVersion = version + (redo?1:-1);						*/
/*		}* 						*/
/*											*/
/*//			this.set = _set;						*/
/*		var checkParent = function (parent, value) {						*/var checkParent=function(){with(_frm(this,arguments,["parent","value"],[])){nj:while(1){switch(_cp){case 0:var c0=
/*			if (value.id && !value.hasOwnProperty("parent")) // the last condition prevents a not ready yet object from getting an improper parent						*/value.id;_cp=(c0)?1:2;break;case 1:_cp=3;case 3:if((_r.v3=value.hasOwnProperty("parent"))===_S){return _s();}c0=!_r.v3;_cp=2;break;case 2:_cp=(c0)?4:5;break;case 4:_cp=6;case 6:if((_r.v6=
/*				pjs._directSet(value,"parent",parent);						*/pjs._directSet(value,"parent",parent))===_S){return _s();}_cp=5;break;case 5:break nj;}}}};
/*		}						*/
/*	/**						*/
/*	 * Clone a persistent object, copying all the persisted fields and deep copying where children are a child according to the parent ancestorship						*/
/*	 * 						*/

/*		pjs.clone = function(object) {						*/pjs.clone=function(){with(_frm(this,arguments,["object"],["subClone","cloneList"])){nj:while(1){switch(_cp){case 0:
/*			if (object.$_funcObj)						*/if(object.$_funcObj)
/*				object = object.$_funcObj;									*/{object=object.$_funcObj;}
/*			var cloneList = {};						*/cloneList={};
/*			var subClone = function(subObject) {						*/subClone=function(){with(_frm(this,arguments,["subObject"],["basis","copy"])){nj:while(1){switch(_cp){case 0:
/*				if (typeof subObject == "object") {						*/_cp=(typeof subObject=="object")?1:2;break;case 1:_cp=3;case 3:if((_r.v3=
/*					if (cloneList[getId(subObject)])						*/getId(subObject))===_S){return _s();}_cp=(cloneList[_r.v3])?4:5;break;case 4:
/*						return cloneList[subObject.id];						*/return cloneList[subObject.id];_cp=6;break;case 5:_cp=7;case 7:if((_r.v7=
/*					else if (pjs.isDescendent(object,subObject)) {						*/pjs.isDescendent(object,subObject))===_S){return _s();}_cp=(_r.v7)?8:9;break;case 8:
/*						var basis = subObject.basis;						*/basis=subObject.basis;
/*						if (basis) {						*/_cp=(basis)?10:11;break;case 10:_cp=13;case 13:if((_r.v13=
/*							basis= subClone(basis);						*/subClone(basis))===_S){return _s();}basis=_r.v13;_cp=14;case 14:if((_r.v14=
/*							var copy = pjs.newInstance(basis);						*/pjs.newInstance(basis))===_S){return _s();}copy=_r.v14;_cp=12;break;case 11:
/*						}						*/
/*						else						*/
/*							var copy = {};						*/copy={};_cp=12;break;case 12:
/*						if (subObject.isList) {						*/_cp=(subObject.isList)?15:16;break;case 15:_cp=17;case 17:if((_r.v17=
/*							makeIntoList(copy,true);						*/makeIntoList(copy,true))===_S){return _s();}_cp=18;case 18:if((_r.v18=
/*							pjs._directSet(copy,"array",[]);						*/pjs._directSet(copy,"array",[]))===_S){return _s();}_cp=16;break;case 16:
/*						}						*/
/*						cloneList[subObject.id] = copy;						*/cloneList[subObject.id]=copy;_cp=19;case 19:if((_r.v19=
/*						pjs.introspect(subObject,function(fieldName) {						*/pjs.introspect(subObject,function(){with(_frm(this,arguments,["fieldName"],["value"])){nj:while(1){switch(_cp){case 0:
/*							if (fieldName != "history") {						*/_cp=(fieldName!="history")?1:2;break;case 1:
/*								if (typeof fieldName == "number") {						*/_cp=(typeof fieldName=="number")?3:4;break;case 3:_cp=6;case 6:if((_r.v6=
/*									var value =subClone(subObject.item(fieldName));						*/subObject.item(fieldName))===_S){return _s();}_cp=7;case 7:if((_r.v7=subClone(_r.v6))===_S){return _s();}value=_r.v7;_cp=8;case 8:if((_r.v8=
/*									checkParent(copy,value);						*/checkParent(copy,value))===_S){return _s();}_cp=9;case 9:if((_r.v9=
/*									copy.array.push(value);						*/copy.array.push(value))===_S){return _s();}_cp=5;break;case 4:_cp=10;case 10:if((_r.v10=
/*								}						*/
/*								else {						*/
/*									var value =subClone(get(subObject,fieldName,1));						*/get(subObject,fieldName,1))===_S){return _s();}_cp=11;case 11:if((_r.v11=subClone(_r.v10))===_S){return _s();}value=_r.v11;_cp=12;case 12:if((_r.v12=
/*									pjs._directSet(copy,fieldName,value);						*/pjs._directSet(copy,fieldName,value))===_S){return _s();}_cp=5;break;case 5:_cp=2;break;case 2:break nj;}}}}))===_S){return _s();}
/*								}						*/
/*							}						*/
/*						});						*/
/*						return copy;								*/return copy;_cp=9;break;case 9:_cp=6;break;case 6:_cp=2;break;case 2:
/*					}						*/
/*				}						*/
/*				return subObject;								*/return subObject;break nj;}}}};
/*			};						*/
/*			if (typeof object == "object")						*/_cp=(typeof object=="object")?1:2;break;case 1:_cp=3;case 3:if((_r.v3=
/*				return subClone(object);						*/subClone(object))===_S){return _s();}return _r.v3;_cp=2;break;case 2:
/*			return object;						*/return object;break nj;}}}};
/*		}									*/

/*								*/
/*			/**						*/
/*			 * Returns 						*/
/*			 * 						*/
/*			pjs.getAccess = function(obj) {						*/pjs.getAccess=function(){with(_frm(this,arguments,["obj"],["getSetter","permParent","i","name","access"])){nj:while(1){switch(_cp){case 0:_cp=1;case 1:if((_r.v1=
/*				var access = get(obj,"access",1);						*/get(obj,"access",1))===_S){return _s();}access=_r.v1;
/*				if (access == NJSuspend) return rerunLater();						*/_cp=(access==NJSuspend)?2:3;break;case 2:_cp=4;case 4:if((_r.v4=rerunLater())===_S){return _s();}return _r.v4;_cp=3;break;case 3:
/*				if (access) {						*/if(access){
/*					access.isAccess = true;						*/access.isAccess=true;
/*					return access;						*/return access;}
/*				}						*/

/*				var permParent = obj;						*/permParent=obj;case 5:_cp=7;case 7:if((_r.v7=
/*				do {						*/
/*					permParent = get(permParent,'parent');						*/get(permParent,"parent"))===_S){return _s();}permParent=_r.v7;
/*					if (permParent == NJSuspend) return NJSuspend;						*/if(permParent==NJSuspend){return NJSuspend;}var c7=
/*					if (!permParent && !obj.hasOwnProperty("id"))						*/!permParent;_cp=(c7)?8:9;break;case 8:_cp=10;case 10:if((_r.v10=obj.hasOwnProperty("id"))===_S){return _s();}c7=!_r.v10;_cp=9;break;case 9:if(c7)
/*						return;						*/{return;}_cp=11;case 11:if((_r.v11=
/*				}	while (!(access = get(permParent,"access",1)));						*/get(permParent,"access",1))===_S){return _s();}_cp=(!(access=_r.v11))?5:6;break;case 6:
/*				if (access == NJSuspend) return NJSuspend;						*/if(access==NJSuspend){return NJSuspend;}
/*				access.isAccess = true;							*/access.isAccess=true;_cp=12;case 12:if((_r.v12=
/*				access = pjs.clone(access);						*/pjs.clone(access))===_S){return _s();}access=_r.v12;_cp=13;case 13:if((_r.v13=
/*				var name = get(access,"name");						*/get(access,"name"))===_S){return _s();}name=_r.v13;
/*				if (name == NJSuspend) return NJSuspend;						*/if(name==NJSuspend){return NJSuspend;}
/*				access.name = name + " (inherited)";							*/access.name=name+" (inherited)";
/*				var getSetter = function (permit) {						*/getSetter=function(permit){
/*					return function(field,value) {						*/return function(){with(_frm(this,arguments,["field","value"],[])){nj:while(1){switch(_cp){case 0:
/*						access.name = name + " (modified)";						*/access.name=name+" (modified)";_cp=1;case 1:if((_r.v1=
/*						set(obj,"access",access);						*/set(obj,"access",access))===_S){return _s();}
/*						permit.set = pjs.proto.set;						*/permit.set=pjs.proto.set;_cp=2;case 2:if((_r.v2=
/*						set(permit,field,value);									*/set(permit,field,value))===_S){return _s();}break nj;}}}};};
/*					}						*/
/*				}						*/
/*				for (var i=0;i<access.getLength();i++) {						*/i=0;case 15:_cp=16;case 16:if((_r.v16=access.getLength())===_S){return _s();}_cp=(i<_r.v16)?17:18;break;case 17:_cp=19;case 19:if((_r.v19=
/*					get(access,i).set = 	getSetter(get(access,i));								*/get(access,i))===_S){return _s();}_cp=20;case 20:if((_r.v20=get(access,i))===_S){return _s();}_cp=21;case 21:if((_r.v21=getSetter(_r.v20))===_S){return _s();}_r.v19.set=_r.v21;case 14:i++;_cp=15;break;case 18:_cp=22;case 22:if((_r.v22=
/*				}						*/
/*				access.set = getSetter(access);						*/getSetter(access))===_S){return _s();}access.set=_r.v22;
/*				return access;						*/return access;break nj;}}}};
/*			}						*/
